/// Author:					Joe Audette
/// Created:				2007-03-05
/// Last Modified:			2009-11-14
/// 
/// The use and distribution terms for this software are covered by the 
/// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)  
/// which can be found in the file CPL.TXT at the root of this distribution.
/// By using this software in any fashion, you are agreeing to be bound by 
/// the terms of this license.
///
/// You must not remove this notice, or any other, from this software.
/// [System.Xml.Serialization.XmlInclude(typeof(CartProduct))]

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Xml.Serialization;
using eStore.Data;
using mojoPortal.Business;
using mojoPortal.Business.Commerce;

namespace eStore.Business
{
    /// <summary>
    /// Represents a shopping cart
    /// </summary>
    [Serializable()]
    public class Cart
    {

        #region Constructors

        public Cart()
        { }


        public Cart(Guid cartGuid)
        {
            GetCart(cartGuid);
        }

        #endregion

        #region Private Properties

        private Guid cartGuid = Guid.Empty;
        private Guid storeGuid = Guid.Empty;
        private Guid userGuid = Guid.Empty;
        //private Guid currencyGuid = Guid.Empty;
        //private Guid languageGuid = Guid.Empty;
        //private decimal currencyValue = 1;
        private decimal subTotal = 0;
        private decimal taxTotal = 0;
        private decimal shippingTotal = 0;
        private decimal discount = 0;
        private decimal orderTotal = 0;
        private DateTime created = DateTime.UtcNow;
        private string createdFromIP = string.Empty;
        private DateTime lastModified = DateTime.UtcNow;
        private DateTime lastUserActivity = DateTime.UtcNow;
        private CartOrderInfo orderInfo = null;
        private bool cartExists = false;
        private Guid newCartID = Guid.NewGuid();

        private string discountCodesCsv = string.Empty;
        private string customData = string.Empty;

        private Guid clerkGuid = Guid.Empty;




        [NonSerializedAttribute()]
        private Store store = null;

        // SoapFormatter can't serialize generic collections
        [NonSerializedAttribute()]
        private List<CartProduct> cartProducts = null;
        //private ArrayList cartItems = new ArrayList();
        private string serializedCartProducts = string.Empty;



        #endregion

        #region Public Properties

        public Guid CartGuid
        {
            get { return cartGuid; }
            set { cartGuid = value; }
        }
        public Guid StoreGuid
        {
            get { return storeGuid; }
            set { storeGuid = value; }
        }

        public Guid ClerkGuid
        {
            get { return clerkGuid; }
            set { clerkGuid = value; }
        }



        public List<CartProduct> CartProducts
        {
            get
            {
                if (cartProducts == null)
                {
                    cartProducts = GetCartProducts();
                }

                if (cartProducts.Count == 0)
                {
                    cartProducts = GetCartProducts();
                }

                return cartProducts;
            }
        }


        //[XmlIgnore]
        public string SerializedCartProducts
        {
            get { return serializedCartProducts; }
            set { serializedCartProducts = value; }
        }

        // This is needed to support xml serialization, string with special characterscan cause invalid xml, base 64 encoding them gets around the problem.

        //[XmlElement(ElementName = "serializedCartProducts", DataType = "base64Binary")]
        //public byte[] ProductSerialization
        //{
        //    get
        //    {
        //        return System.Text.Encoding.Unicode.GetBytes(SerializedCartProducts);
        //    }
        //    set
        //    {
        //        SerializedCartProducts = System.Text.Encoding.Unicode.GetString(value);
        //    }
        //}  



        public Guid UserGuid
        {
            get { return userGuid; }
            set { userGuid = value; }
        }


        public CartOrderInfo OrderInfo
        {
            get
            {
                if (orderInfo == null)
                {
                    orderInfo = new CartOrderInfo(this.cartGuid);
                    if (
                        (!orderInfo.Exists)
                        && (this.userGuid != Guid.Empty)
                        )
                    {
                        EnsureStore();
                        store.LoadCustomerInfoFromMostRecentOrder(this);

                    }
                }
                return orderInfo;
            }

        }

        //public Guid CurrencyGuid
        //{
        //    get { return currencyGuid; }
        //    set { currencyGuid = value; }
        //}
        //public decimal CurrencyValue
        //{
        //    get { return currencyValue; }
        //    set { currencyValue = value; }
        //}
        public decimal SubTotal
        {
            get { return subTotal; }
            set { subTotal = value; }
        }
        public decimal ShippingTotal
        {
            get { return shippingTotal; }
            set { shippingTotal = value; }
        }

        public decimal TaxTotal
        {
            get { return taxTotal; }
            set { taxTotal = value; }
        }

        public decimal Discount
        {
            get { return discount; }
            set { discount = value; }
        }

        public decimal OrderTotal
        {
            get { return orderTotal; }
            set { orderTotal = value; }
        }
        public DateTime Created
        {
            get { return created; }
            set { created = value; }
        }
        public string CreatedFromIP
        {
            get { return createdFromIP; }
            set { createdFromIP = value; }
        }
        public DateTime LastModified
        {
            get { return lastModified; }
            set { lastModified = value; }
        }
        public DateTime LastUserActivity
        {
            get { return lastUserActivity; }
            set { lastUserActivity = value; }
        }

        public bool Exists
        {
            get { return cartExists; }

        }

        public string DiscountCodesCsv
        {
            get { return discountCodesCsv; }
            set { discountCodesCsv = value; }
        }

        public string CustomData
        {
            get { return customData; }
            set { customData = value; }
        }

        #endregion

        #region Private Methods

        private void EnsureStore()
        {
            if (store == null) store = new Store(storeGuid);

        }

        private void GetCart(Guid cartGuid)
        {
            using (IDataReader reader = DBCart.GetCart(cartGuid))
            {
                GetCart(reader);
            }

        }

        private void GetCart(IDataReader reader)
        {
            if (reader.Read())
            {
                this.cartExists = true;
                this.cartGuid = new Guid(reader["CartGuid"].ToString());
                this.storeGuid = new Guid(reader["StoreGuid"].ToString());
                this.userGuid = new Guid(reader["UserGuid"].ToString());

                this.subTotal = Convert.ToDecimal(reader["SubTotal"]);
                this.shippingTotal = Convert.ToDecimal(reader["ShippingTotal"]);
                this.taxTotal = Convert.ToDecimal(reader["TaxTotal"]);
                this.discount = Convert.ToDecimal(reader["Discount"]);
                this.orderTotal = Convert.ToDecimal(reader["OrderTotal"]);
                this.created = Convert.ToDateTime(reader["Created"]);
                this.createdFromIP = reader["CreatedFromIP"].ToString();
                this.lastModified = Convert.ToDateTime(reader["LastModified"]);
                this.lastUserActivity = Convert.ToDateTime(reader["LastUserActivity"]);

                this.customData = reader["CustomData"].ToString();
                this.discountCodesCsv = reader["DiscountCodesCsv"].ToString();
                if (reader["ClerkGuid"] != DBNull.Value)
                {
                    this.clerkGuid = new Guid(reader["ClerkGuid"].ToString());
                }

            }

        }

        private bool Create()
        {

            this.cartGuid = this.newCartID;

            int rowsAffected = DBCart.AddCart(
                this.cartGuid,
                this.storeGuid,
                this.userGuid,
                this.subTotal,
                this.shippingTotal,
                this.taxTotal,
                this.orderTotal,
                this.created,
                this.createdFromIP,
                this.lastModified,
                this.lastUserActivity,
                this.discount,
                this.discountCodesCsv,
                this.customData,
                this.clerkGuid);

            return (rowsAffected > 0);

        }



        private bool Update()
        {

            return DBCart.UpdateCart(
                this.cartGuid,
                this.userGuid,
                this.subTotal,
                this.shippingTotal,
                this.taxTotal,
                this.orderTotal,
                this.lastModified,
                this.lastUserActivity,
                this.discount,
                this.discountCodesCsv,
                this.customData,
                this.clerkGuid);

        }


        private void CalculateSubTotal()
        {
            decimal calculatedSubTotal = 0;
            foreach (CartProduct cartProduct in CartProducts)
            {
                calculatedSubTotal += (cartProduct.Quantity * cartProduct.ProductPrice);

            }
            EnsureStore();

            this.subTotal = Math.Round(calculatedSubTotal, store.RoundingDecimalPlaces, store.RoundingMode);
            if (subTotal < 0) { subTotal = 0; }

        }

        public void ResetCartProducts()
        {
            cartProducts = null;
        }

        private void CalculateTaxTotal()
        {
            EnsureStore();
            store.CalculateTax(this);


        }

        private void CalculateTotal()
        {
            EnsureStore();
            decimal total = (this.subTotal + this.shippingTotal + this.taxTotal) - this.discount;
            this.orderTotal = Math.Round(total, store.RoundingDecimalPlaces, store.RoundingMode);
            if (orderTotal < 0) { orderTotal = 0; }

        }

        private List<CartProduct> GetCartProducts()
        {

            List<CartProduct> cartProducts = CartProduct.GetByCart(this.cartGuid);

            //IDataReader reader = DBCartProduct.GetByCart(this.cartGuid, Guid.Empty);
            //while (reader.Read())
            //{
            //    CartProduct cartProduct = new CartProduct();

            //    cartProduct.AddedToCart = Convert.ToDateTime(reader["AddedToCart"]);
            //    cartProduct.CartGuid = this.cartGuid;
            //    cartProduct.CurrencyGuid = new Guid(reader["CurrencyGuid"].ToString());
            //    cartProduct.ItemGuid = new Guid(reader["ItemGuid"].ToString());
            //    cartProduct.ProductGuid = new Guid(reader["ProductGuid"].ToString());
            //    cartProduct.ProductPrice = Convert.ToDecimal(reader["ProductPrice"]);
            //    cartProduct.PriceGuid = new Guid(reader["PriceGuid"].ToString());
            //    cartProduct.Quantity = Convert.ToInt32(reader["Quantity"]);
            //    cartProduct.TaxClassGuid = new Guid(reader["TaxClassGuid"].ToString());
            //    cartProducts.Add(cartProduct);

            //}
            //reader.Close();

            return cartProducts;

        }

        #endregion

        #region Public Methods


        public bool Save()
        {
            if (this.cartGuid != Guid.Empty)
            {
                this.lastModified = DateTime.UtcNow;
                return Update();
            }
            else
            {
                return Create();
            }
        }

        public void LoadExistingUserCartIfExists()
        {
            if (this.userGuid == Guid.Empty) return;

            using (IDataReader reader = DBCart.GetByUser(userGuid, storeGuid))
            {
                GetCart(reader);
            }

        }

        public void ClearCustomerData()
        {
            this.OrderInfo.CustomerEmail = string.Empty;
            this.OrderInfo.CustomerCompany = string.Empty;
            this.OrderInfo.CustomerAddressLine1 = string.Empty;
            this.OrderInfo.CustomerAddressLine2 = string.Empty;
            this.OrderInfo.CustomerCity = string.Empty;
            this.OrderInfo.CustomerFirstName = string.Empty;
            this.OrderInfo.CustomerLastName = string.Empty;
            this.OrderInfo.CustomerPostalCode = string.Empty;
            this.OrderInfo.CustomerState = string.Empty;
            this.OrderInfo.CustomerCountry = string.Empty;
            this.OrderInfo.CustomerTelephoneDay = string.Empty;
            this.OrderInfo.CustomerTelephoneNight = string.Empty;

            this.OrderInfo.BillingCompany = string.Empty;
            this.OrderInfo.BillingAddress1 = string.Empty;
            this.OrderInfo.BillingAddress2 = string.Empty;
            this.OrderInfo.BillingCity = string.Empty;
            this.OrderInfo.BillingFirstName = string.Empty;
            this.OrderInfo.BillingLastName = string.Empty;
            this.OrderInfo.BillingPostalCode = string.Empty;
            this.OrderInfo.BillingState = string.Empty;
            this.OrderInfo.BillingCountry = string.Empty;

            this.OrderInfo.DeliveryCompany = string.Empty;
            this.OrderInfo.DeliveryAddress1 = string.Empty;
            this.OrderInfo.DeliveryAddress2 = string.Empty;
            this.OrderInfo.DeliveryCity = string.Empty;
            this.OrderInfo.DeliveryFirstName = string.Empty;
            this.OrderInfo.DeliveryLastName = string.Empty;
            this.OrderInfo.DeliveryPostalCode = string.Empty;
            this.OrderInfo.DeliveryState = string.Empty;
            this.OrderInfo.DeliveryCountry = string.Empty;


        }

        public void CopyShippingToBilling()
        {
            this.OrderInfo.BillingCompany = this.OrderInfo.DeliveryCompany;
            this.OrderInfo.BillingAddress1 = this.OrderInfo.DeliveryAddress1;
            this.OrderInfo.BillingAddress2 = this.OrderInfo.DeliveryAddress2;
            this.OrderInfo.BillingCity = this.OrderInfo.DeliveryCity;
            this.OrderInfo.BillingFirstName = this.OrderInfo.DeliveryFirstName;
            this.OrderInfo.BillingLastName = this.OrderInfo.DeliveryLastName;
            this.OrderInfo.BillingPostalCode = this.OrderInfo.DeliveryPostalCode;
            this.OrderInfo.BillingState = this.OrderInfo.DeliveryState;
            this.OrderInfo.BillingCountry = this.OrderInfo.DeliveryCountry;

        }

        public void CopyBillingToShipping()
        {
            this.OrderInfo.DeliveryCompany = this.OrderInfo.BillingCompany;
            this.OrderInfo.DeliveryAddress1 = this.OrderInfo.BillingAddress1;
            this.OrderInfo.DeliveryAddress2 = this.OrderInfo.BillingAddress2;
            this.OrderInfo.DeliveryCity = this.OrderInfo.BillingCity;
            this.OrderInfo.DeliveryFirstName = this.OrderInfo.BillingFirstName;
            this.OrderInfo.DeliveryLastName = this.OrderInfo.BillingLastName;
            this.OrderInfo.DeliveryPostalCode = this.OrderInfo.BillingPostalCode;
            this.OrderInfo.DeliveryState = this.OrderInfo.BillingState;
            this.OrderInfo.DeliveryCountry = this.OrderInfo.BillingCountry;

        }

        public void CopyCustomerToBilling()
        {
            this.OrderInfo.BillingCompany = this.OrderInfo.CustomerCompany;
            this.OrderInfo.BillingAddress1 = this.OrderInfo.CustomerAddressLine1;
            this.OrderInfo.BillingAddress2 = this.OrderInfo.CustomerAddressLine2;
            this.OrderInfo.BillingCity = this.OrderInfo.CustomerCity;
            this.OrderInfo.BillingFirstName = this.OrderInfo.CustomerFirstName;
            this.OrderInfo.BillingLastName = this.OrderInfo.CustomerLastName;
            this.OrderInfo.BillingPostalCode = this.OrderInfo.CustomerPostalCode;
            this.OrderInfo.BillingState = this.OrderInfo.CustomerState;
            this.OrderInfo.BillingCountry = this.OrderInfo.CustomerCountry;

        }

        public void CopyShippingToCustomer()
        {
            this.OrderInfo.CustomerCompany = this.OrderInfo.DeliveryCompany;
            this.OrderInfo.CustomerAddressLine1 = this.OrderInfo.DeliveryAddress1;
            this.OrderInfo.CustomerAddressLine2 = this.OrderInfo.DeliveryAddress2;
            this.OrderInfo.CustomerCity = this.OrderInfo.DeliveryCity;
            this.OrderInfo.CustomerFirstName = this.OrderInfo.DeliveryFirstName;
            this.OrderInfo.CustomerLastName = this.OrderInfo.DeliveryLastName;
            this.OrderInfo.CustomerPostalCode = this.OrderInfo.DeliveryPostalCode;
            this.OrderInfo.CustomerState = this.OrderInfo.DeliveryState;
            this.OrderInfo.CustomerCountry = this.OrderInfo.DeliveryCountry;

        }



        public void CopyCustomerToShipping()
        {
            this.OrderInfo.DeliveryCompany = this.OrderInfo.CustomerCompany;
            this.OrderInfo.DeliveryAddress1 = this.OrderInfo.CustomerAddressLine1;
            this.OrderInfo.DeliveryAddress2 = this.OrderInfo.CustomerAddressLine2;
            this.OrderInfo.DeliveryCity = this.OrderInfo.CustomerCity;
            this.OrderInfo.DeliveryFirstName = this.OrderInfo.CustomerFirstName;
            this.OrderInfo.DeliveryLastName = this.OrderInfo.CustomerLastName;
            this.OrderInfo.DeliveryPostalCode = this.OrderInfo.CustomerPostalCode;
            this.OrderInfo.DeliveryState = this.OrderInfo.CustomerState;
            this.OrderInfo.DeliveryCountry = this.OrderInfo.CustomerCountry;

        }




        public bool AddProductToCart(Product product, int quantity)
        {
            if (product == null) { return false; }

            bool foundProductInCart = false;
            bool deleted = false;
            foreach (CartProduct cProduct in CartProducts)
            {
                if (cProduct.ProductGuid == product.Guid)
                {
                    foundProductInCart = true;
                    cProduct.Quantity += quantity;
                    if (cProduct.Quantity <= 0)
                    {
                        DBCartProduct.Delete(cProduct.ItemGuid);
                        ResetCartProducts();
                        deleted = true;
                    }
                    else
                    {
                        cProduct.Save();
                    }
                    RefreshTotals();
                    Save();
                }
            }

            if (foundProductInCart)
            {
                return !deleted;
            }

            if (quantity <= 0) { return false; }

            CartProduct cartProduct = new CartProduct
                                          {
                                              CartGuid = cartGuid,
                                              TaxClassGuid = product.TaxClassGuid,
                                              ProductGuid = product.Guid,
                                              ProductPrice = product.Price,
                                              Quantity = quantity,
                                              Tax = 0,
                                              IsDonation = product.IsDonation
                                          };
            //cartProduct.CurrencyGuid = currencyGuid;
            // this will be updated later, just initialize to 0
            cartProduct.Save();

            // clear products collection so it will be refreshed
            cartProducts = GetCartProducts();

            //CalculateSubTotal();
            //CalculatShippingTotal();
            //CalculateTaxTotal();
            //CalculateTotal();
            //Save();
            RefreshTotals();


            return true;
        }

        public bool UpdateCartItemQuantity(Guid itemGuid, int quantity)
        {
            foreach (CartProduct cartProduct in CartProducts)
            {
                if (cartProduct.ItemGuid == itemGuid)
                {
                    if (quantity <= 0)
                    {
                        DBCartProduct.Delete(itemGuid);
                        ResetCartProducts();
                    }
                    else
                    {
                        cartProduct.Quantity = quantity;
                        cartProduct.Save();
                    }

                    RefreshTotals();
                    Save();

                    return true;
                }

            }

            return false;

        }

        public void ClearItems()
        {
            foreach (CartProduct o in CartProducts)
            {
                DeleteItem(o.ItemGuid);
            }
            ResetCartProducts();
            RefreshTotals();
        }

        public bool DeleteItem(Guid itemGuid)
        {
            bool result = DBCartProduct.Delete(itemGuid);

            if (result)
            {
                RefreshTotals();
                Save();
            }

            return result;

        }

        public IDataReader GetItems()
        {
            return DBCartProduct.GetByCart(this.cartGuid);

        }

        public List<CartProduct> GetProducts()
        {
            return CartProduct.GetByCart(this.cartGuid);

        }

        /// <summary>
        /// Found out 2008-08-25 that you can't use google checkout to take donations unless you are a tax exempt non profit
        /// https://checkout.google.com/support/sell/bin/answer.py?answer=75724
        /// 
        /// Donation solicitations from parties without a valid 501(c)(3) tax exempt status clearly displayed to the public; 
        /// solicitations from parties without valid proof of exempt tax status or proof of registration with the relevant country's 
        /// regulatory bodies and authorities; and political organizations that have registered with the FEC.
        /// </summary>
        /// <returns></returns>
        public bool HasDonations()
        {
            foreach (CartProduct product in CartProducts)
            {
                if (product.IsDonation) { return true; }
            }

            return false;
        }

        public bool HasProduct(Guid productGuid)
        {
            foreach (CartProduct product in CartProducts)
            {
                if (product.ProductGuid == productGuid) { return true; }
            }

            return false;
        }

        public void ResetUserInfo()
        {
            CartOrderInfo info = new CartOrderInfo();
            info.CartGuid = this.cartGuid;
            info.Save();
            orderInfo = info;
        }

        public void RefreshTotals()
        {
            CalculateSubTotal();
            CalculateTaxTotal();
            CalculateTotal();
            Save();

        }


        public void SerializeCartProducts()
        {
            //if (cartProducts == null)
            //{
            //    cartProducts = GetCartProducts();
            //}

            ArrayList arrayList = new ArrayList();
            foreach (CartProduct c in CartProducts)
            {

                arrayList.Add(SerializationHelper.RemoveXmlDeclaration(SerializationHelper.SerializeToString(c)));

            }

            this.serializedCartProducts = SerializationHelper.RemoveXmlDeclaration(SerializationHelper.SerializeToString(arrayList));

        }


        public void DeSerializeCartProducts()
        {


            if (this.serializedCartProducts.Length == 0) return;
            ArrayList arrayList = SerializationHelper.DeserializeFromString(typeof(ArrayList),
                SerializationHelper.RestoreXmlDeclaration(this.serializedCartProducts)) as ArrayList;

            if (arrayList == null) return;

            if (this.cartProducts == null) this.cartProducts = new List<CartProduct>();

            if (this.cartProducts.Count > 0) this.cartProducts.Clear();

            foreach (string c in arrayList)
            {
                CartProduct product = SerializationHelper.DeserializeFromString(typeof(CartProduct),
                    SerializationHelper.RestoreXmlDeclaration(c)) as CartProduct;

                this.cartProducts.Add(product);
            }

        }


        #endregion

        #region Static Methods

        public static bool Delete(Guid cartGuid)
        {
            CartProduct.DeleteByCart(cartGuid);
            CartOrderInfo.Delete(cartGuid);

            return DBCart.DeleteCart(cartGuid);
        }

        public static bool DeleteAnonymousByStore(Guid storeGuid, DateTime olderThan)
        {
            CartProduct.DeleteAnonymousByStore(storeGuid, olderThan);
            CartOrderInfo.DeleteAnonymousByStore(storeGuid, olderThan);

            return DBCart.DeleteAnonymousByStore(storeGuid, olderThan);
        }

        public static bool DeleteByStore(Guid storeGuid, DateTime olderThan)
        {
            CartProduct.DeleteByStore(storeGuid, olderThan);
            CartOrderInfo.DeleteByStore(storeGuid, olderThan);

            return DBCart.DeleteByStore(storeGuid, olderThan);
        }


        /// <summary>
        /// Gets a page of data from the ws_Cart table.
        /// </summary>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="totalPages">total pages</param>
        public static IDataReader GetPage(
            Guid storeGuid,
            int pageNumber,
            int pageSize,
            out int totalPages)
        {
            return DBCart.GetPage(
                storeGuid,
                pageNumber,
                pageSize,
                out totalPages);

        }


        /*
        // TODO: uncomment and implement if needed
        public static DataTable GetPage(int pageNumber, int pageSize)
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("CartGuid",typeof(Guid));
            dataTable.Columns.Add("StoreGuid",typeof(Guid));
            dataTable.Columns.Add("UserGuid",typeof(Guid));
            dataTable.Columns.Add("CurrencyGuid",typeof(Guid));
            dataTable.Columns.Add("CurrencyValue",typeof(decimal));
            dataTable.Columns.Add("SubTotal",typeof(decimal));
            dataTable.Columns.Add("TaxTotal",typeof(decimal));
            dataTable.Columns.Add("OrderTotal",typeof(decimal));
            dataTable.Columns.Add("Created",typeof(DateTime));
            dataTable.Columns.Add("CreatedFromIP",typeof(string));
            dataTable.Columns.Add("LastModified",typeof(DateTime));
            dataTable.Columns.Add("LastUserActivity",typeof(DateTime));
            dataTable.Columns.Add("TotalPages", typeof(int));
		
            IDataReader reader = DBCart.GetCartPage(pageNumber, pageSize);	
            while (reader.Read())
            {
                DataRow row = dataTable.NewRow();
                row["CartGuid"] = reader["CartGuid"];
                row["StoreGuid"] = reader["StoreGuid"];
                row["UserGuid"] = reader["UserGuid"];
                row["CurrencyGuid"] = reader["CurrencyGuid"];
                row["CurrencyValue"] = reader["CurrencyValue"];
                row["SubTotal"] = reader["SubTotal"];
                row["TaxTotal"] = reader["TaxTotal"];
                row["OrderTotal"] = reader["OrderTotal"];
                row["Created"] = reader["Created"];
                row["CreatedFromIP"] = reader["CreatedFromIP"];
                row["LastModified"] = reader["LastModified"];
                row["LastUserActivity"] = reader["LastUserActivity"];
                row["TotalPages"] = Convert.ToInt32(reader["TotalPages"]);
                dataTable.Rows.Add(row);
            }
		
            reader.Close();
		
            return dataTable;
		
        }
	
        */

        #endregion


    }

}
